<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use app\common\model\Users;
use  think\Session;

class Login extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //

        if (IS_POST) {

            $post = input('post.');
            $user = Users::where('username', '=', $post['username'])->where('is_admin', '=', 1)->find();

            if (!$user || $user['password'] != md5($post['password'])) {
                $this->error('用户名或者密码错误');
            } else {
                Session::set('user', $user->toArray());

                $this->success('登陆成功', 'Index/index');
            }

        }


        return view();

    }

    public function layout()
    {

        // 清除当前请求有效的session
        Session::delete('user');
//        Session::delete('cart');
        $this->success('退出成功', '/admin/login/index');

    }

}
